package com.rc.saas.tenant.controller.member;

import com.rc.saas.tenant.base.TenantBaseController;
import com.rc.saas.tenant.common.vo.TResponse;
import com.rc.saas.tenant.model.member.MemberAccountRecord;
import com.rc.saas.tenant.service.member.MemberRefundOrderService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Create by Yang on 2021/9/17
 */
@RestController
@RequestMapping("/memberRefundOrder")
public class MemberRefundOrderController extends TenantBaseController {

    private static Logger logger = LogManager.getLogger(MemberRefundOrderController.class);

    @Autowired
    private MemberRefundOrderService memberRefundOrderService;

    /**
     * @param rechargeOrderId
     * @param refundType      退款订单类型 (0.可退 1不可退)
     */
    @RequestMapping(value = "/memberRefundOrderInsert", method = RequestMethod.POST)
    public TResponse memberRefundOrderInsert(@RequestBody Long rechargeOrderId, String refundType) {
        if (refundType.equals("0")) {
            //添加可退款订单表
            memberRefundOrderService.insertByRechargeOrder(rechargeOrderId);
            return TResponse.SUCCESS();
        } else if (refundType.equals("1")) {
            //添加不可退订单表
            memberRefundOrderService.insertByRechargeOrder(rechargeOrderId);
            return TResponse.SUCCESS();
        }
        return TResponse.FAIL("无效退款类型");
    }


    /**
     *
     * @param memberAccountRecord
     * @return
     */
    @RequestMapping(value = "/updateByMemberAccountRecord", method = RequestMethod.POST)
    public TResponse updateByMemberAccountRecord(@RequestBody MemberAccountRecord memberAccountRecord) {

        //添加变动记录
        memberRefundOrderService.updateByMemberAccountRecord(memberAccountRecord);
        return TResponse.SUCCESS();
    }

}
